
import 'package:flutter/cupertino.dart';
import 'package:item_detail_demo/item_detail/components/item_desc.dart';
import 'package:item_detail_demo/item_detail/components/item_images.dart';
import 'package:item_detail_demo/item_detail/components/item_price.dart';
import 'package:item_detail_demo/item_detail/components/item_xianyuhao.dart';
import 'package:item_detail_demo/item_detail/components/recommend_title.dart';
import 'package:item_detail_demo/item_detail/components/user_title.dart';


typedef ComponentBuilder = Widget Function();

class ItemDetailManager {
  static ItemDetailManager instance = ItemDetailManager();

  late Map<String, ComponentBuilder> registerCenter;

  void setup() {
    registerCenter = <String, ComponentBuilder> {
      'user_title': () => const UserTitle(),
      'item_price': () => const ItemPrice(),
      'item_desc': () => const ItemDesc(),
      'item_images': () => const ItemImages(),
      'item_xianyuhao': () => const ItemXianyuhao(),
      'recommend_title': () => const RecommendTitle(),
    };
  }

  void registerComponent(String key, ComponentBuilder builder) {
    assert(registerCenter.isNotEmpty);
    registerCenter[key] = builder;
  }

  Widget buildComponent(String key) {
    assert(registerCenter.isNotEmpty);
    if (registerCenter.containsKey(key)) {
      return registerCenter[key]!();
    }
    return Container();
  }

}